import type { State } from '..';
import http from "@/utils/http";
import type { MutationTree, ActionTree, GetterTree } from 'vuex'



export interface SystemsState {
    banners: any[]
    notices: any[]
    detailContent: object
    [index: string]: any
}


const state: SystemsState = {
    banners: [],
    notices: [],
    detailContent: {}
}


const mutations: MutationTree<SystemsState> = {
    updateDatas(state, data) {
        state[data.key] = data.data
    }
}

const actions: ActionTree<SystemsState, State> = {
    getNotice(_, data) {
        http.get('/system/article/notice').then((res: any) => {
            if (res.code === 0) {
                _.commit('updateDatas', {
                    key: 'notices',
                    data: res.data
                })
            }
        })
    },
    getBanner(_, data) {
        http.get('/system/article/banner').then((res: any) => {
            if (res.code === 0) {
                _.commit('updateDatas', {
                    key: 'banners',
                    data: res.data
                })
            }
        })
    },
}

const getters: GetterTree<SystemsState, State> = {

}


export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}